package com.ztesoft.web.ssh;

import java.io.IOException;
import java.io.InputStream;

import com.jcraft.jsch.ChannelExec;
import com.jcraft.jsch.JSchException;

public class PublicSSHExec {
	public String execNormalCommand(ChannelExec channel,String command) throws IOException, JSchException{
		channel.setCommand(command);
//	    channel.connect(30000);
	    channel.connect();
		InputStream in=channel.getInputStream();
	    byte[] tmp=new byte[1024];
	    StringBuffer buffer=new StringBuffer();
	    while(true){
	    	while(in.available()>0){
	    		int i=in.read(tmp, 0, 1024);
	    		if(i<0)break;
	    		buffer.append(new String(tmp, 0, i));
	        }
	        if(channel.isClosed()){
	          if(in.available()>0) continue;
	          break;
	        }
	    }
		return buffer.toString();
	}
}
